{extend name="$_admin_layout"}

{block name="tpl_vars"}
    {eq name="_request_action" value="create"}
        {php}$page_title = '新建菜单';{/php}
    {else /}
        {php}$page_title = '修改菜单：' . $menu_info['title'];{/php}
    {/eq}
{/block}

{block name="main-content"}
    <form id="menu_form" class="form form-manager">
        <div class="box box-default no-heading">
            <div class="box-body">

                <div class="row">
                    <div class="col-sm-12">
                        {:helper('admin/form')->render_group('pid', $menu_info['pid'], 'select', '上级', null, array('list' => $parent_list, 'key_field' => 'id', 'title_field' => '_title_show'))}
                        {:helper('admin/form')->render_group('type', $menu_info['type'], 'select', '类型', null, array('list' => $menu_type_list))}
                        
                        <div class="hidden well menu-type click">
                            {:helper('admin/form')->render_group('content[click][key]', isset($menu_info['content']['click']['key']) ? $menu_info['content']['click']['key'] : '', 'text', 'Key')}
                        </div>
                        <div class="hidden well menu-type view">
                            {:helper('admin/form')->render_group('content[view][url]', isset($menu_info['content']['view']['url']) ? $menu_info['content']['view']['url'] : '', 'text', '网址')}
                        </div>
                        <div class="hidden well menu-type scancode_waitmsg">
                            {:helper('admin/form')->render_group('content[scancode_waitmsg][key]', isset($menu_info['content']['scancode_waitmsg']['key']) ? $menu_info['content']['scancode_waitmsg']['key'] : '', 'text', 'Key')}
                        </div>
                        <div class="hidden well menu-type scancode_push">
                            {:helper('admin/form')->render_group('content[scancode_push][key]', isset($menu_info['content']['scancode_push']['key']) ? $menu_info['content']['scancode_push']['key'] : '', 'text', 'Key')}
                        </div>
                        <div class="hidden well menu-type pic_sysphoto">
                            {:helper('admin/form')->render_group('content[pic_sysphoto][key]', isset($menu_info['content']['pic_sysphoto']['key']) ? $menu_info['content']['pic_sysphoto']['key'] : '', 'text', 'Key')}
                        </div>
                        <div class="hidden well menu-type pic_photo_or_album">
                            {:helper('admin/form')->render_group('content[pic_photo_or_album][key]', isset($menu_info['content']['pic_photo_or_album']['key']) ? $menu_info['content']['pic_photo_or_album']['key'] : '', 'text', 'Key')}
                        </div>
                        <div class="hidden well menu-type pic_weixin">
                            {:helper('admin/form')->render_group('content[pic_weixin][key]', isset($menu_info['content']['pic_weixin']['key']) ? $menu_info['content']['pic_weixin']['key'] : '', 'text', 'Key')}
                        </div>
                        <div class="hidden well menu-type location_select">
                            {:helper('admin/form')->render_group('content[location_select][key]', isset($menu_info['content']['location_select']['key']) ? $menu_info['content']['location_select']['key'] : '', 'text', 'Key')}
                        </div>
                        <div class="hidden well menu-type media_id">
                            {:helper('admin/form')->render_group('content[media_id][media_id]', isset($menu_info['content']['media_id']['media_id']) ? $menu_info['content']['media_id']['media_id'] : '', 'text', 'Media ID')}
                        </div>
                        <div class="hidden well menu-type view_limited">
                            {:helper('admin/form')->render_group('content[view_limited][media_id]', isset($menu_info['content']['view_limited']['media_id']) ? $menu_info['content']['view_limited']['media_id'] : '', 'text', 'Media ID')}
                        </div>
                        <div class="hidden well menu-type miniprogram">
                            {:helper('admin/form')->render_group('content[miniprogram][url]', isset($menu_info['content']['miniprogram']['url']) ? $menu_info['content']['miniprogram']['url'] : '', 'text', 'URL')}
                            {:helper('admin/form')->render_group('content[miniprogram][appid]', isset($menu_info['content']['miniprogram']['appid']) ? $menu_info['content']['miniprogram']['appid'] : '', 'text', 'AppID')}
                            {:helper('admin/form')->render_group('content[miniprogram][pagepath]', isset($menu_info['content']['miniprogram']['pagepath']) ? $menu_info['content']['miniprogram']['pagepath'] : '', 'text', 'PagePagh')}
                        </div>
                        
                        {:helper('admin/form')->render_group('title', $menu_info['title'], 'text', '标题')}
                        {:helper('admin/form')->render_group('sort', $menu_info['sort'], 'text', '排序')}
                        {:helper('admin/form')->render_group('status', $menu_info['status'], 'status', '状态')}
                        {:helper('admin/form')->render_hidden('mp_id', $menu_info['mp_id'])}
                        {:helper('admin/form')->render_submit_and_cancel(request()->url(), $_controller->url('index'))}

                        <script type="text/javascript">
                            $(function(){
                                $('#menu_form').bootstrapValidator({
                                    fields: {
                                        title: {
                                            validators: {
                                                notEmpty: {
                                                    message: '标题不能为空。',
                                                },
                                            },
                                        },
                                    },
                                });
                                
                                function toggleMenuType(mt) {
                                	$('#menu_form .menu-type').each(function() {
                                        if ($(this).hasClass(mt)) {
                                        	$(this).removeClass('hidden');
                                        } else {
                                        	$(this).addClass('hidden');
                                        }
                                    });
                                }
                                
                                toggleMenuType('{$menu_info.type}');
                                
                                $('#menu_form select[name=type]').change(function() {
                                	toggleMenuType($(this).val());
                                });
                            });
                        </script>
                    </div>
                </div>

            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </form>
{/block}